package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {

        /* reportDate: null,
        todayNewMember: 0,
        totalMember: 0,
        thisWeekNewMember: 0,
        thisMonthNewMember: 0,
        todayOrderNumber: 0,
        todayVisitsNumber: 0,
        thisWeekOrderNumber: 0,
        thisWeekVisitsNumber: 0,
        thisMonthOrderNumber: 0,
        thisMonthVisitsNumber: 0,
        hotSetMeal: [
                    {name: '阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐', setmeal_count: 200, proportion: 0.222},
                    {name: '阳光爸妈升级肿瘤12项筛查体检套餐', setmeal_count: 200, proportion: 0.222}
                ]*/

        Map<String,Object> result = new HashMap<>();
        //获取今日的日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周的周一的日期
        String monday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月第一天
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());


        Integer todayNewMember = memberDao.findMemberCountByDate(today);//今日新增会员
        Integer totalMember = memberDao.findMemberTotalCount();//会员总数
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(monday);//本周新增会员数
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);//本月新增会员数

        Integer  todayOrderNumber = orderDao.findOrderCountByDate(today);//今日预约数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);//今日到访会员数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(monday);//本周预约的会员数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(monday);//本周到访的会员数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);//本月预约的会员数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);//本月到访的会员数

        List<Map> hotSetmeal = orderDao.findHotSetmeal();



        result.put("reportDate",today);
        result.put("todayNewMember",todayNewMember);
        result.put("totalMember",totalMember);
        result.put("thisWeekNewMember",thisWeekNewMember);
        result.put("thisMonthNewMember",thisMonthNewMember);
        result.put("todayOrderNumber",todayOrderNumber);
        result.put("thisWeekOrderNumber",thisWeekOrderNumber);
        result.put("thisMonthOrderNumber",thisMonthOrderNumber);
        result.put("todayVisitsNumber",todayVisitsNumber);
        result.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        result.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        result.put("hotSetMeal",hotSetmeal);

        return result;
    }
}
